package com.sc.service.impl.csm;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.domain.HouseholdLabel;
import com.sc.dto.HouseholdLabelDTO;
import com.sc.mapper.csm.HouseholdLabelMapper;
import com.sc.service.csm.IHouseholdLabelService;
import org.springframework.stereotype.Service;

@Service
public class HouseholdLabelServiceImpl extends ServiceImpl<HouseholdLabelMapper, HouseholdLabel> implements IHouseholdLabelService {

    @Override
    public Page<HouseholdLabel> pageQuery(HouseholdLabelDTO householdLabelDTO) {
        QueryWrapper<HouseholdLabel> wrapper = Wrappers.emptyWrapper();
        String labelName = householdLabelDTO.getLabelName();

        if (labelName != null && !labelName.isEmpty()) {
            wrapper = new QueryWrapper<>();
            wrapper.like("label_name", labelName);
        }

        Page<HouseholdLabel> page = new Page<>(householdLabelDTO.getPageNum(), householdLabelDTO.getPageSize());
        Page<HouseholdLabel> householdLabelPage = page(page, wrapper);
        return householdLabelPage;
    }
}
